/**
 * 
 */
package page;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @version January 7, 2012
 * @author Jay Fernandez
 * 
 * 
 */
public class PageAnalyzer {
	/*
	 * Number of pages
	 */
	/**
	 * Keywords list 
	 */
	private ArrayList<String> keywords = new ArrayList<String>();
	/**
	 * Map for keeping count of keywords
	 */
	private HashMap<String, Integer> mapKeywords = new HashMap<String, Integer>();
	public PageAnalyzer(ArrayList<String> givenKeywords) {
		for (int i = 0; i < givenKeywords.size(); i++){
			keywords.add(givenKeywords.get(i));
			mapKeywords.put(givenKeywords.get(i), 0);
		}
	}
	public static void main(String args[]) {
		String test = "black sheep wall <a href=\"http://someplatform.xxx/directory/page.html\"> hello my name is fred what is yours haha yours sucks blah <a href=\"http://someplatform.yyy/directory/page.html\">";
		ArrayList<String> listtest = new ArrayList<String>();
		PageAnalyzer blah = new PageAnalyzer(listtest);
		blah.analyzePage(test);
	}
	/*public PageAnalyzer() {
		analyzePage(test);
	}*/
	
	public void analyzePage(String page) {
		boolean finished = false;
		int start = 0;
		while (!finished){
			int index = page.indexOf("<a href", start);
			System.out.println("index: " + index);
			if (index >= 0) { 
				int index2 = page.indexOf(">", index);
				System.out.println("index2: " + index2);
				String newString = page.substring(index + 9, index2 - 1);
				System.out.println(newString);
				start = index2 + 1;
				//send the new URL to pageRetriever.
			} else {
				finished = true;
			}
		}
		
		
		
		
	}
	
	public void analyzeKeywords(ArrayList<String> page) {
		 
		for (int i = 0; i < page.size(); i++){
			for (int j = 0; j < keywords.size(); j++){
				if (page.get(i).equals(keywords.get(j))){
					mapKeywords.put(keywords.get(j), mapKeywords.get(keywords.get(j)) + 1) ;
				}
			}
		}
	}
	
	public void displayStatistics() {
		//statistics go here
	}
}
